;--------------------------------
; Test file for 68000 assembler.
;
; snasm68.exe
;--------------------------------

; ===================================================================
; ===================================================================
; ===================================================================

; Purpose:
; - Code to load extra data files

	org $1ff000

start:
;	movea.l #text1_file_name,a3	; script file
;	movea.l #$120000,a2		; dst address
;	jsr $1fffec.l

	; ----------------------------

	movea.l $1fffe0,a0		; compression area
	subq.l #4,a0
	move.l #$14d814d8,d0		; data bytes
	move.w #$30-1,d1		; amount to restore (~$c0 bytes)

restore_compression:
	move.l d0,(a0)+			; RESTORE LZ decoder area
	dbra d1, restore_compression

	; ----------------------------

	movea.l #decoder_boot,a0	; replace decoder ENTRY
	movea.l $1fffe4,a1
	subq.l #4,a1

	move.w (a0)+,(a1)+		; copy JMP instruction
	move.l (a0)+,(a1)+

	move.l a1,$1fffe4		; NEW normal routine entry

	; ----------------------------

	movem.l (a7)+,D0-D3/A0-A3	; restore DISK_LOAD vars

	movea.l $1fffe8,a7		; restore STACK
	bra.s begin_decoder		; normal decoder routine


text1_file_name:
	dc.b "text1",0
	even

decoder_boot:
	jmp begin_decoder

; =================================
; *********************************
; *********************************
; =================================

begin_decoder:

	; save STACK
	move.l a7,$1fffe8.l

	; switch stacks (RAM space limited)
	movea.l #$1fffe0,a7

; ================================
; ================================

	; DO bypass here

; ================================
; ================================

	; OLD code
	movem.l D1-D3/A0-A4,-(a7)
	move.w #$00ff,d3


	; CALL decoder
	pea (callback_decoder)
	move.l $1fffe4,-(a7)
	rts


callback_decoder:
	; OLD code
	movem.l (a7)+,d1-d3/a0-a4
	sub.l a2,d0

; ================================
; ================================

	; 'USERDISK MAKE' - dst / size
	cmpa.l #$87628,a2
	cmp.l #$1fdb8,d0
	bne exit_decoder

; --------------------------------

	; DO slipstreaming here
	movem.l a0-a1/d0,-(a7)

	movea.l #$1ff100,a0

; --------------------------------

copy_loop1:
	; copy PTR-32 to PTR-32
	move.l (a0)+,d0
	movea.l (a0)+,a1
	move.l d0,(a1)

	; check EOS
	tst.b (a0)
	beq copy_loop1

; --------------------------------

	movem.l (a7)+,a0-a1/d0
	bra exit_decoder

; ================================
; ================================

exit_decoder:
	; restore STACK
	movea.l $1fffe8,a7
	rts
